<?php
class IndexController extends AbstractController
{
	public function init()
	{
		parent::init();
		$this->switchContext(array('login'=>'json','openinghours'=>'json'));
	}
		
	
	public function indexAction()
	{
		$this->addTitle('Main');
		$this->addJs('/js/index.js');
	}

	public function openinghoursAction()
	{
		$openinghoursModel = new Itc_Model_DbTable_OpeningHours();

		$params = $this->request->getParams();

		$data = $openinghoursModel->getGridData($params,$this->view);
	}

	public function loginAction()
	{
		$loginData = $this->request->getPost();
		$authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
		$authAdapter->setTableName('doctor');
		$authAdapter->setIdentityColumn('login')
					->setCredentialColumn('pass')
					->setIdentity($loginData['login'])
					->setCredential($loginData['pass']);
		$auth = Zend_Auth::getInstance();
		if($auth->authenticate($authAdapter)->isValid()){
			$identity = $authAdapter->getResultRowObject();
			$auth->getStorage()->write($identity);

			$this->view->success = true;
		}else{
			$this->view->success = false;
		}
	}
}
